﻿

using System;

namespace DanGao.Infrastructure.IO
{
    /// <summary>
    /// 配置文件工具
    /// </summary>
    public class AppSettingUtils
    {
        /// <summary>
        /// 获取配置文件节点
        /// </summary>
        /// <param name="key">键</param>
        /// <returns></returns>
        public static T AppSettings<T>(string key)
        {
            return AppSettings<T>(key, default(T));
        }

        /// <summary>
        /// 获取带默认值配置文件节点 
        /// </summary>
        /// <param name="key">键</param>
        /// <param name="defaultValue">默认值</param>
        /// <returns></returns>
        public static T AppSettings<T>(string key, T defaultValue)
        {
            var value = System.Configuration.ConfigurationManager.AppSettings[key];
            return string.IsNullOrEmpty(value) ? defaultValue : (T)Convert.ChangeType(value, typeof(T));
        }
    }

}

